package com.atguigu;

import com.atguigu.bean.Person;
import com.atguigu.config.MainConfig;
import com.atguigu.config.MainConfig2;
import com.atguigu.controller.BookController;
import com.atguigu.dao.BookDao;
import com.atguigu.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest {

    public static void main(String[] args) {
        //ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        //Person person = (Person) context.getBean("person");
        //System.out.println(person);
        //
        //BookController controller = context.getBean(BookController.class);
        //BookService bookService = context.getBean(BookService.class);
        //BookDao bookDao = context.getBean(BookDao.class);
        //System.out.println(controller+":"+bookService+":"+bookDao);


        ApplicationContext context = new AnnotationConfigApplicationContext(MainConfig2.class);
        Person person = context.getBean(Person.class);
        System.out.println(person);

        String[] beanNamesForType = context.getBeanNamesForType(Person.class);
        for (String beanName : beanNamesForType) {
            System.out.println(beanName);
        }

        printBeans(context);
    }

    private static void printBeans(ApplicationContext context){
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String name : beanDefinitionNames) {
            System.out.println(name);
        }
    }
}
